import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:industry_net/base/common/util.dart';
import 'package:industry_net/base/component/component.dart';

import 'controller.dart';

class LoginPage extends GetView<LoginController> {
  const LoginPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: presentAppBar(context),
      backgroundColor: ColorsUtil.white,
      body: WillPopScope(
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 31.w),
            child: Column(
              children: [
                SizedBox(
                  height: 46.w,
                ),
                Obx(
                  () => Text(
                    controller.state.isCodeLogin.value ? '验证码登录' : '密码登录',
                    style: pfSCStyle(color: ColorsUtil.title, fontSize: 24.sp),
                  ),
                ),
                SizedBox(
                  height: 40.w,
                ),
                UITextField(
                  controller: controller.state.accountCtrl,
                  name: '账号',
                  hintText: '请输入账号',
                ),
                // SizedBox(
                //   height: 20.w,
                // ),
                Obx(() => Visibility(
                      visible: !controller.state.isCodeLogin.value,
                      child: UITextField(
                          controller: controller.state.pwdCtrl,
                          name: '密码',
                          hintText: '请输入密码',
                          obscureText: controller.state.obscureText.value,
                          suffixIcon: InkWell(
                            onTap: () {
                              controller.state.obscureText.value =
                                  !controller.state.obscureText.value;
                            },
                            child: Icon(
                              controller.state.obscureText.value == true
                                  ? IconUtil.eye_close
                                  : IconUtil.eye_open,
                              color: ColorsUtil.content,
                              size: 15.w,
                            ),
                          )),
                    )),
                Obx(() => Visibility(
                      visible: controller.state.isCodeLogin.value,
                      child: CodeField(
                        controller: controller.state.pwdCtrl,
                      ),
                    )),
                SizedBox(
                  height: 51.w,
                ),
                ExpandedButton(
                  text: '登录',
                  onPressed: controller.login,
                ),
                SizedBox(
                  height: 24.w,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    RichText(
                      text: TextSpan(
                          text: '没有账号？',
                          style: pfMediumStyle(
                            color: ColorsUtil.content,
                            fontSize: font14,
                          ),
                          children: [
                            TextSpan(
                              text: '立即注册',
                              recognizer: controller.state.registerGesture,
                              style: pfMediumStyle(
                                  color: ColorsUtil.blue, fontSize: font14),
                            ),
                          ]),
                    ),
                    RichText(
                      text: TextSpan(
                        text: '忘记密码',
                        recognizer: controller.state.forgotGesture,
                        style: pfMediumStyle(
                          color: ColorsUtil.content,
                          fontSize: font14,
                        ),
                      ),
                    ),
                  ],
                ),
                const Spacer(),
                Text(
                  '其他登录方式',
                  style: pfSCStyle(
                      color: ColorsUtil.placeholder, fontSize: font12),
                ),
                SizedBox(
                  height: 20.w,
                ),
                GetBuilder<LoginController>(
                  builder: (_) {
                    return Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: controller.state.loginTypes
                          .map((e) => MenuItemView(
                              onTap: e.onTap,
                              icon: loadImage(
                                  url: e.url!.imgPathMe,
                                  width: 40.w,
                                  height: 40.w),
                              title: Text(
                                e.name,
                                style: pfMediumStyle(
                                    color: ColorsUtil.subTitle,
                                    fontSize: font12),
                              )))
                          .toList(),
                    );
                  },
                ),
                SizedBox(
                  height: SizeFit.safeBottom,
                ),
              ],
            ),
          ),
          onWillPop: () async {
            return false;
          }),
    );
  }
}
